//
//  UITextFieldExtensions.swift
//  Fangxukanghan
//
//  Created by 常超群的MacBookPro on 2021/4/16.
//

import Foundation
/// 给view添加边框
public extension UITextField {
    
    /// 添加图片
    /// - Parameters:
    ///   - image: 图片
    ///   - padding: 间距
    func ccq_addPaddingLeftIcon(_ image: UIImage, padding: CGFloat, clickClosure: ((UIButton) -> Void)? = nil) {
        
        let view = UIView(frame: CGRect(x: 0, y: 0, width: image.size.width + padding, height: image.size.height))
        
        let imageBtn = UIButton(type: .custom)
        imageBtn.frame = view.frame
        imageBtn.setImage(image, for: .normal)
        imageBtn.adjustsImageWhenHighlighted = false
        view.addSubview(imageBtn)
        leftView = view
        leftViewMode = .always
        imageBtn.ccq_addTarget { (sender) in
            clickClosure?(sender)
        }
    }
    
    /// 添加图片
    /// - Parameters:
    ///   - image: 图片
    ///   - padding: 间距
    func ccq_addPaddingRightIcon(_ image: UIImage, padding: CGFloat, clickClosure: ((UIButton) -> Void)? = nil) {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: image.size.width + padding, height: image.size.height))
        let imageBtn = UIButton(type: .custom)
        imageBtn.frame = view.frame
        imageBtn.setImage(image, for: .normal)
        imageBtn.adjustsImageWhenHighlighted = false
        view.addSubview(imageBtn)
        rightView = view
        rightViewMode = .always
        imageBtn.ccq_addTarget { (sender) in
            clickClosure?(sender)
        }
    }
    func ccq_addPaddingRingt(_ padding: CGFloat) {
        let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: padding, height: frame.height))
        rightView = paddingView
        rightViewMode = .always
    }
}
